<?php
/**
 * $Id: user.php 24 2009-06-11 05:17:09Z eyou80 $
 */

/**
 * 用户数据类
 *
 * @package App
 */
class App_Abstract_User extends App_Abstract
{
	protected function __metaData()
	{
		return unserialize($this->meta);
	}

	protected function getPageOffset($column, $offset, $group = null, $pageSize = 2)
	{
		$select = $this->db->select(array('COUNT(*)' => 'num'))->from('table.member')->where("table.member.{$column} > {$offset}");

		if(!empty($group)) {
			$select->where('table.member.group = ?', $group);
		}

		$count = $this->db->fetchObject($select)->num + 1;
		return ceil($count / $pageSize);
	}

	public function select()
	{
		return $this->db->select()->from('table.member');
	}

	public function size(Tinyask_Db_Sql $condition)
	{
		return $this->db->fetchObject($condition->select(array('COUNT(*)' => 'num'))->from('table.member'))->num;
	}

	public function insert(array $row)
	{
		return $this->db->query($this->db->insert('table.member')->row($row));
	}

	public function update(array $row, Tinyask_Db_Sql $condition)
	{
		return $this->db->query($condition->update('table.member')->row($row));
	}

	public function delete(Tinyask_Db_Sql $condition)
	{
		return $this->db->query($condition->delete('table.member'));
	}
}
